package com.wiserp.rest.helper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import com.wiserp.rest.model.QtyInLoc;

public class CommonDBUtil {
	public static List<QtyInLoc> findQtyInLocByProdNoAndBatchNo(String prodNo,String batchNo,JdbcTemplate template){
		return template.query("SELECT hcc004,hcc010 FROM shc03 WHERE hcc003=? AND hcc019=? AND hcc005='1'",
				new RowMapper<QtyInLoc>() {
					public QtyInLoc mapRow(ResultSet rs, int i)
							throws SQLException {
						QtyInLoc data = new QtyInLoc();
						data.setWhLocNo(rs.getString("hcc004"));
						data.setQty(rs.getDouble("hcc010"));
						return data;
					}
				},prodNo,batchNo);
	}
	
	public static List<QtyInLoc> findQtyInLocByProdNoAndBatchNoAnd(String prodNo,String batchNo,JdbcTemplate template){
		return template.query("SELECT hcc003,hcc019,hcc004,SUM(hcc010) qty FROM shc03  WHERE hcc003=? AND hcc019=? group by hcc003,hcc019,hcc004",
				new RowMapper<QtyInLoc>() {
					public QtyInLoc mapRow(ResultSet rs, int i)
							throws SQLException {
						QtyInLoc data = new QtyInLoc();
						data.setWhLocNo(rs.getString("hcc004"));
						data.setQty(rs.getDouble("qty"));
						return data;
					}
				},prodNo,batchNo);
	}
}
